﻿ @*
 * ---------------------------------------------------
 * 作者: MTQ 
 * 日期： 2021/5/6 12:46:16 
 * ---------------------------------------------------
 *@
@using MTQ.BLL; 
@{     
   ViewBag.Title = "Index"; 
   Layout = "~/Views/Shared/_Layout_lay_admin.cshtml";    
}    
 <div class="layuimini-container">
   
   <div class="layuimini-main">  
       <fieldset class="table-search-fieldset">                               
            <legend formeld="html" formeld_key="legend">@ViewBag.TitleSearch</legend>                           
             <div style="margin: 10px 10px 10px 10px">                         
                 <form class="layui-form" action="#">                     
                    <div class="layui-form-item">                  
                           <div class="layui-inline">           
                                   <label class="layui-form-label">@ViewBag.SearchKey</label>    
                                      <div class="layui-input-inline">
                                        <input type="text" name="keyword" id="keyword" autocomplete="off" class="layui-input"> 
                                   </div>   
                            </div>      
                                      
                                      
                                      
                                      
                                      
                             <div class="layui-inline">         
                                  <button id="btn-search" class="layui-btn " lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> <span formeld="html" formeld_key="searchbutton">@ViewBag.Search </span></button>    
                             </div>         
                       </div>              
                     </form>                  
                  </div>                    
               </fieldset>                       
                <button type="button" class="layui-btn" id="btnupload" style="display:none"><i class="layui-icon"></i>上传文件</button>                       
               <table class="layui-hide formeldboard" id="currentTableId" lay-filter="currentTableFilter"></table>                       
                <script type="text/html" id="currentTableBar">                       
                      <a ex_btn="ex_edit" class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">@ViewBag.Edit</a>                
                 </script>                     
                 <script type="text/html" id="toolbarDemo">                     
                     <div class="layui-btn-container">                 
                          <button ex_btn="ex_add" class="layui-btn layui-btn-sm data-add-btn" lay-event="add"> @ViewBag.Add </button>              
                          <button ex_btn="ex_upload" class="layui-btn layui-btn-sm data-add-btn" lay-event="upload"> @ViewBag.Upload </button>              
                            <button ex_btn="ex_delete" class="layui-btn layui-btn-sm layui-btn-danger data-count-delete" lay-event="delete">@ViewBag.Delete</button>           
                           <button ex_btn="ex_export" class="layui-btn layui-btn-sm layui-btn-normal" lay-event="export">  @ViewBag.Export </button>           
                     </div>                 
                  </script>                    
             </div>                         
          </div>                            
     <script type="text/javascript">                                 
          var table;                             
           var reloadTable = function (sortField, sortType) {                            
               var startdate = $("#startdate").val();                          
               var enddate = $("#enddate").val();                       
               var keyword = $("#keyword").val();                       
                                      
               table.reload('currentTableId', {                       
                    where: { //设定异步数据接口的额外参数，任意设                   
                         keyword: keyword,              
                         startdate: startdate,             
                         enddate: enddate,             
                         sortField: sortField,            
                         sortType: sortType             
                     }                
               });                        
             }                         
                                      
         layui.use(['form', 'table', 'upload','laydate'], function () {                             
            var $ = layui.jquery,                          
                laydate=layui.laydate,                      
                 form = layui.form;                      
             var upload = layui.upload;                          
             window.table = layui.table;                         
                                      
            //指定允许上传的文件类型                          
             upload.render({                          
                 elem: '#btnupload'                      
                 , url: '/Base_LocalUser/UploadFile' //改成您自己的上传接口                     
                 , accept: 'file' //普通文件                     
                 , done: function (res) {                     
                     if (res.success) {                  
                      layer.msg('上传成功');                
                       reloadTable('LU_ID','asc');                
                      } else {                 
                        layer.msg('上传失败');               
                      }                 
                   }                   
               });                       
                                      
              laydate.render({                         
                    elem: '#startdate'                   
              });                        
              laydate.render({                        
                     elem: '#enddate'                 
              });                         
                                      
             table.on('toolbar(currentTableFilter)', function (obj) {                         
                if (obj.event === 'upload') {  // 监听添加操作                      
                   $("#btnupload").click();                   
                                      
                } else if (obj.event === 'add') {                       
                   var index = layer.open({               
                       title: '添加',          
                       type: 2,          
                       shade: 0.2,          
                       maxmin: true,          
                       area: ['800px', '580px'],          
                       content: '/Base_LocalUser/Create',          
                    });             
                    $(window).on("resize", function () {              
                     layer.full(index);             
                     });              
                 } else if (obj.event === 'delete') {  // 监听删除操作                     
                       var checkStatus = table.checkStatus('currentTableId');                
                       var data = checkStatus.data;               
                       layer.confirm('确定要禁用选中的账户吗？', function () {               
                           var arrId = [];            
                           for (var i = 0; i < data.length; i++) {           
                              arrId.push(data[i].LU_ID);        
                            }          
                          var strIds = arrId.join(',');            
                          $.ajax({            
                            url: '/Base_LocalUser/ActivateSwich',           
                            type: 'post',          
                            dataType: 'text',          
                            data: { "primarykeys": strIds },           
                            success: function (resp) {          
                                  var json = eval('(' + resp + ')');      
                                  layer.alert(json.Message);    
                                  reloadTable('LU_ID','asc');    
                             },          
                             error: function (resp) {         
                                    layer.alert("对不起出错了");   
                             }         
                           })            
                        })               
                     } else if (obj.event === 'export') {                  
                      var keyword = $("#keyword").val();                
                      var startdate = $("#startdate").val();                          
                      var enddate = $("#enddate").val();                       
                      var url = "/Base_LocalUser/Export?keyword=" + keyword + "&startdate=" + startdate + "&enddate=" + enddate;                
                       window.location.href = url;                
                     }                 
                    });                   
                                      
               //监听表格复选框选择                       
               table.on('checkbox(currentTableFilter)', function (obj) {                       
                });                       
                                      
                table.on('tool(currentTableFilter)', function (obj) {                       
                     var data = obj.data;                 
                     if (obj.event === 'edit') {                 
                          var index = layer.open({             
                          title: 'Edit',            
                          type: 2,            
                          shade: 0.2,            
                          maxmin: true,            
                          area: ['700px', '580px'],            
                           content: '/Base_LocalUser/Edit?primarykey=' + data.LU_ID,            
                       });               
                      $(window).on("resize", function () {                 
                         layer.full(index);             
                       });                
                      return false;                 
                    }                  
                 });                      
                                      
                  table.on('sort(currentTableFilter)', function (obj) {                     
                         reloadTable(obj.field, obj.type);              
                   });                    
                                      
                  $('#btn-search').click(function () {                    
                       reloadTable('LU_ID','asc');                
                       return false;               
                    });                   
                                      
                                      
                    var _url = '/Base_LocalUser/Search';                   
                     table.render({                  
                          elem: '#currentTableId',             
                          url: _url,            
                          toolbar: '#toolbarDemo',            
                          defaultToolbar: ['filter'],            
                          cols: [[            
                               { type: "checkbox", width: 50 },       
                                      
      { field: 'User_Id', width: 200, title: base_localuser_entity.User_Id },      
      { field: 'LanguageName', width: 200, title: base_localuser_entity.LanguageName },      
                                      
                                      
                                { title: '操作', minWidth:80, toolbar: '#currentTableBar', align: "center" ,fixed: 'right'},      
                                      
                               ]],       
                            limits: [10, 15, 20, 25, 50, 100],          
                            limit: 10,          
                            page: true          
                       });                
                       reloadTable('LU_ID','asc');                
                 });                      
         </script>                             
                                      
                                      
                                      
                                      
                                      

